package com.service.device;

import com.common.ErrorCodeEnum;
import com.common.emums.DataStatus;
import com.common.exception.BusinessException;
import com.common.utils.StringUtils;
import com.core.springSecurity.common.SecurityUtils;

import com.dao.secondary.device.DeviceObdBaseInfoMapper;
import com.dao.secondary.device.DeviceObdRepairRecordInfoMapper;
import com.model.domain.device.GetDeviceObdBaseInfoDO;
import com.model.pojo.device.DeviceObdBaseInfo;
import com.model.pojo.device.DeviceObdRepairRecordInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.github.pagehelper.PageHelper;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @Author: zql
 * @Description: OBD设备工厂维修记录服务
 * @Data: 2023-07-09
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DeviceObdRepairRecordInfoService {

    private final DeviceObdRepairRecordInfoMapper deviceObdRepairRecordInfoMapper;
    private final DeviceObdBaseInfoService deviceObdBaseInfoService;
    @Transactional
    public List<DeviceObdBaseInfo> saveRepairInfo(DeviceObdRepairRecordInfo info){
        GetDeviceObdBaseInfoDO getDeviceObdBaseInfoDO = new GetDeviceObdBaseInfoDO();
        getDeviceObdBaseInfoDO.setImei(info.getImei());
        getDeviceObdBaseInfoDO.setSortRow("id");
        List<DeviceObdBaseInfo> tempList = new ArrayList<>();
        String dtus = "";
        List<DeviceObdBaseInfo> list = deviceObdBaseInfoService.getAllList(getDeviceObdBaseInfoDO);
        if(list!=null && list.size()>0){
            for(DeviceObdBaseInfo baseInfo :list){
                baseInfo.setBatchId(null);
                baseInfo.setCartonNo(null);
                baseInfo.setLon("");
                baseInfo.setLat("");
                baseInfo.setImei("");
                baseInfo.setSim("");
                baseInfo.setWjdy("");
                baseInfo.setGgyxh("");
                baseInfo.setCjbs("");
                baseInfo.setCjzt(0);
                baseInfo.setModuleType("");
                baseInfo.setEepromDeleteCount("");
                baseInfo.setHasPass(0);
                baseInfo.setHasPass2(0);
                baseInfo.setCheckoutTime(null);
                baseInfo.setCheckoutTime2(null);
                baseInfo.setLastModifiedTime(new Date());
                tempList.add(baseInfo);
                dtus+=baseInfo.getDtu()+";";
            }
            deviceObdBaseInfoService.updateList(tempList);
            info.setDtu(dtus);
            info.setCreateTime(new Date());
            deviceObdRepairRecordInfoMapper.insertSelective(info);
        }

        return tempList;
    }
}
